package com.sss.support.web.actions;

import java.io.File;

import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.sss.support.service.GSBDataImporter;

@Result(name = "JSON", type = "json", params = { "enableGZIP", "true",
		"noCache", "true", "ignoreHierarchy", "false" })
public class Upload extends ActionSupport {
	private static final Logger log = LoggerFactory.getLogger(Upload.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 3902953189893678379L;

	@Autowired GSBDataImporter importer;
	
	
	private File upload;
	private String uploadContentType;
	private String uploadFileName;
	private String fileCaption;
	
	private String start;
	private String end;

	// flag
	private boolean success;
	private String msg;
	public void setUpload(File upload) {
		this.upload = upload;
	}

	public File getUpload() {
		return upload;
	}

	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public String getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setFileCaption(String fileCaption) {
		this.fileCaption = fileCaption;
	}

	public String getFileCaption() {
		return fileCaption;
	}
	
	
	public void setSuccess(boolean success) {
		this.success = success;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getMsg() {
		return msg;
	}

	@Override
	public String execute() throws Exception {
		log.info("[ starting upload... {} ]",this.getFileCaption());
		try{
			
			importer.importDeadManToDB(getUpload(), Integer.valueOf(getStart()), Integer.valueOf(getEnd()));
			
			this.setSuccess(true);
		}catch(Exception e){
			this.setSuccess(false);
		}
		return "JSON";//relevant w/ name
	}

	public void setStart(String start) {
		this.start = start;
	}

	public String getStart() {
		return start;
	}

	public void setEnd(String end) {
		this.end = end;
	}

	public String getEnd() {
		return end;
	}

	
}
